package freespiritsocial.io.user.ui.fragment.account

import android.os.Bundle
import androidx.core.os.bundleOf
import freespiritsocial.io.user.R
import freespiritsocial.io.user.base.BaseFragment
import freespiritsocial.io.user.databinding.FrgForgetPasswordBinding
import freespiritsocial.io.user.ext.setTitle
import freespiritsocial.io.user.handle.BackHandle
import freespiritsocial.io.user.viewmodel.ForgetViewModel
import me.hgj.jetpackmvvm.ext.nav
import me.hgj.jetpackmvvm.ext.navigateAction

class ForgotFrg: BaseFragment<ForgetViewModel,FrgForgetPasswordBinding>() {
    override fun layoutId(): Int = R.layout.frg_forget_password

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewModel = mViewModel
        mDatabind.click = Click()
        mDatabind.root.setTitle(getString(R.string.forgot_password))
        initCcp()
    }

    private fun initCcp() {
//        mDatabind.includedPhone.ccp.registerCarrierNumberEditText(mDatabind.includedPhone.etPhoneNumber)
        mDatabind.includedPhone.ccp.setOnCountryChangeListener {
            mViewModel.countryCode.set(mDatabind.includedPhone.ccp.selectedCountryCodeWithPlus)
        }
    }

    inner class Click: BackHandle {
        override fun goBack() {
            nav().navigateUp()
        }

        fun submit() {
            mViewModel.checkMobile {
                nav().navigateAction(
                    R.id.action_forgotFrg_to_resetPasswordFrg2,
                    bundleOf("phoneNumber" to mViewModel.phoneNumber.get().replace(" ",""),"countryCode" to mViewModel.countryCode.get())
                )
            }
        }
    }
}